/*
 * @Author: lll 1280388921@qq.com
 * @Date: 2025-05-08 23:06:06
 * @LastEditors: lll 1280388921@qq.com
 * @LastEditTime: 2025-05-12 23:11:35
 * @FilePath: /lesson39/2.blockqueue/Task.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#pragma once
#include <iostream>
#include<string>
using namespace std;

string opers="+-*/%";

enum
{
    Div_zero = 1,
    Mod_zero,
    Unknown
};

class Task
{
public:
    Task(){}
    Task(int x, int y, char op)
        : a(x), b(y), op_(op), ret(0), exitcode(0)
    {
    }
    void Run()
    {
        switch (op_)
        {
        case '+':
            ret = a + b;
            break;
        case '-':
            ret = a - b;
            break;
        case '*':
            ret = a * b;
            break;
        case '/':
        {
            if (b == 0)
                exitcode = Div_zero;
            else
                ret = a / b;
        }
        break;
        case '%':
        {
            if (b == 0)
                exitcode = Mod_zero;
            else
                ret = a % b;
        }
        break;
        default:
            exitcode=Unknown;
            break;
        }
    }
    string GetTask()
    {
        string r=to_string(a);
        r+=op_;
        r+=to_string(b);
        r+="=???";
        return r;
    }
    string Getret()
    {
        string r=to_string(a);
        r+=op_;
        r+=to_string(b);
        r+="=";
        r+=to_string(ret);
        r+=" [ exitcode: ";
        r+=to_string(exitcode);
        r+=" ]";
        return r;
    }
    void operator()()
    {
        Run();
    }
    ~Task() {}

private:
    int a;
    int b;
    char op_;

    int ret;
    int exitcode;
};